package com.smzd.ccms.domain;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Date;

import com.smzd.core.domain.BaseIntIdEntity;
import com.smzd.utils.SimpleDateTimeUtil;

public class Dict extends BaseIntIdEntity {
	private static final long serialVersionUID = -4864188921551567894L;
	// key
	private String key;
	// value
	private String value;
	// 类型
	private Integer type;
	// 用于修改时的原先值的保存
	private String oldValue;
	
	private String alias;

	private int source;


	public Dict() {
	}

	public Dict(int id) {
		super(id);
	}

	public Dict(Dict dict) {
		this.name = dict.name;
		this.description = dict.description;
		this.key = dict.key;
		this.value = dict.value;
		this.type = dict.type;
	}

	/**
	 * 获取key
	 * 
	 * @return
	 */
	public String getKey() {
		return key;
	}

	/**
	 * 设置key
	 * 
	 * @param key
	 */
	public void setKey(String key) {
		this.key = key;
	}

	/**
	 * 获取value
	 * 
	 * @return
	 */
	public String getValue() {
		return value;
	}

	/**
	 * 设置value
	 * 
	 * @param value
	 */
	public void setValue(String value) {
		this.value = value;
	}

	/**
	 * 获取类型
	 * 
	 * @return
	 */
	public Integer getType() {
		return type;
	}

	/**
	 * 设置类型
	 * 
	 * @param type
	 */
	public void setType(Integer type) {
		this.type = type;
	}

	public String getOldValue() {
		return oldValue;
	}

	public void setOldValue(String oldValue) {
		this.oldValue = oldValue;
	}

	public String stringValue() {
		String value = this.value;
		try {
			value = URLDecoder.decode(value, "utf-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return value;
	}

	public int intValue() {
		return Integer.parseInt(value);
	}

	public double realValue() {
		return Double.parseDouble(value);
	}

	public boolean booleanValue() {
		return Boolean.parseBoolean(value);
	}

	public Date dateValue() {
		return SimpleDateTimeUtil.parse(value);
	}

	public Object varValue() {
		Object value = null;
		switch (type) {
		case 0:
			value = stringValue();
			break;
		case 1:
			value = intValue();
			break;
		case 2:
			value = realValue();
			break;
		case 3:
			value = booleanValue();
			break;
		case 4:
			value = dateValue();
			break;
		default:
			break;
		}
		return value;
	}

	public String getAlias() {
		return alias;
	}

	public void setAlias(String alias) {
		this.alias = alias;
	}

	public int getSource() {
		return source;
	}

	public void setSource(int source) {
		this.source = source;
	}
}
